# Updated by Wei on 2013/07/13 night
# Just do NOT know what function do this program perform (STOP using it currently) 

# Note: the folloiwng training file can be attained from the following command:
# sort -g --key=1 Posting_Oriented_Training_Dataset_2013_02_22.train_tfqAdded_labelsAdded_sortedByTerm_rankInListAdded_sortedByDocID_rankInDocAdded_freqInCollectionAdded > Posting_Oriented_Training_Dataset_2013_02_22.train_tfqAdded_labelsAdded_sortedByTerm_rankInListAdded_sortedByDocID_rankInDocAdded_freqInCollectionAdded_sortedByQueryID
inputFileName = "/home/diaosi/gov2ClearYourMindAndDoItAgain/Posting_Oriented_Training_Dataset_2013_02_22.train_tfqAdded_labelsAdded_sortedByTerm_rankInListAdded_sortedByDocID_rankInDocAdded_freqInCollectionAdded_sortedByQueryID"
inputFileHandler = open(inputFileName,"r")
oldHeadLine = inputFileHandler.readline()
newHeadLine = oldHeadLine

outputFileName = "/home/diaosi/gov2ClearYourMindAndDoItAgain/Posting_Oriented_Training_Dataset_2013_02_22.train_tfqAdded_labelsAdded_sortedByTerm_rankInListAdded_sortedByDocID_rankInDocAdded_freqInCollectionAdded_sortedByQueryID_fixed"
outputFileHandler = open(outputFileName,"w")
outputFileHandler.write(newHeadLine)

for line in inputFileHandler.readlines():
    lineElements = line.strip().split(" ")
    newLine = ""
    for element in lineElements[0:10]:
        newLine += element + " "
    
    if lineElements[10] == "TOP10":
        newLine += "True" + " "
    elif lineElements[10] == "NotTOP10":
        newLine += "False" + " "
    
    for element in lineElements[11:14]:
        newLine += element + " "
    
    newLine += "\n"
    
    outputFileHandler.write( newLine )


inputFileHandler.close()
outputFileHandler.close()
